import 'package:flutter_admin/utils/utils.dart';

class PurchaseQualityProblem {
  ///
  /// 反馈单创建
  ///@Author: chendeji
  ///@Date: 2022-05-24 09:23:21
  ///
  static const CREATED = '';

  ///
  /// 反馈单确认发送
  ///@Author: chendeji
  ///@Date: 2022-05-24 09:32:23
  ///
  static const SENDED = '0';

  ///
  /// 供应商提交最新的原因分析和改进措施
  ///@Author: chendeji
  ///@Date: 2022-05-24 09:32:42
  ///
  static const SUBMIT_CAURSE = '1';

  ///
  /// 客户退回
  ///@Author: chendeji
  ///@Date: 2022-05-24 09:33:19
  ///
  static const REFUSE = '2';

  String? id;
  String? serialnumber;
  // String? productId;
  String? productName;
  String? documentno;
  String? spec;
  // String? supplierId;
  String? supplierName;
  String? resaon;
  String? instockdate;
  String? instockqty;
  num? checkqty;
  num? unqualifiedqty;
  String? questiondescription;
  String? treatmentmethod;
  String? causeanalysis;
  String? rectificationmeasures;
  String? effectiveverification;
  String? status;
  String? handleuserId;
  String? handleuserName;
  String? handledatetime;
  String? createUid;
  String? createName;
  String? createDate;
  String? createDateStart;
  String? createDateEnd;
  String? writeUid;
  String? writeDate;
  String? jianyanren;
  String? jcrq; // 检验日期
  String? cgb; // 采购员
  String? zlbpsyj; // 处理方式
  String? isPush; // 是否供应商可见
  String? bhx; // 文档号
  String? comfirmTime;
  String? lastSupOpTime;
  String? lastRefuseTime;

  PurchaseQualityProblem(
      {this.id,
      this.serialnumber,
      // this.productId,
      this.productName,
      this.documentno,
      this.spec,
      this.resaon,
      // this.supplierId,
      this.supplierName,
      this.instockdate,
      this.instockqty,
      this.checkqty,
      this.unqualifiedqty,
      this.questiondescription,
      this.treatmentmethod,
      this.causeanalysis,
      this.rectificationmeasures,
      this.effectiveverification,
      this.status: CREATED, // 初始化为创建
      this.handleuserId,
      this.handleuserName,
      this.handledatetime,
      this.createUid,
      this.createName,
      this.createDate,
      this.createDateStart,
      this.createDateEnd,
      this.writeUid,
      this.writeDate,
      this.jianyanren,
      this.jcrq,
      this.cgb,
      this.zlbpsyj,
      this.isPush,
      this.bhx,
      this.comfirmTime,
      this.lastSupOpTime,
      this.lastRefuseTime});

  PurchaseQualityProblem copyWith(
      {String? id,
      String? serialnumber,
      String? documentno,
      String? productId,
      String? spec,
      String? supplierId,
      String? instockdate,
      String? resaon,
      String? instockqty,
      num? checkqty,
      num? unqualifiedqty,
      String? questiondescription,
      String? treatmentmethod,
      String? causeanalysis,
      String? rectificationmeasures,
      String? effectiveverification,
      String? status,
      String? handleuserId,
      String? handledatetime,
      String? createUid,
      String? createDate,
      String? writeUid,
      String? writeDate,
      String? comfirmTime,
      String? lastSupOpTime,
      String? lastRefuseTime}) {
    return new PurchaseQualityProblem(
        id: id ?? this.id,
        serialnumber: serialnumber ?? this.serialnumber,
        documentno: documentno ?? this.documentno,
        resaon: resaon ?? this.resaon,
        // productId: productId ?? this.productId,
        spec: spec ?? this.spec,
        // supplierId: supplierId ?? this.supplierId,
        instockdate: instockdate ?? this.instockdate,
        instockqty: instockqty ?? this.instockqty,
        checkqty: checkqty ?? this.checkqty,
        unqualifiedqty: unqualifiedqty ?? this.unqualifiedqty,
        questiondescription: questiondescription ?? this.questiondescription,
        treatmentmethod: treatmentmethod ?? this.treatmentmethod,
        causeanalysis: causeanalysis ?? this.causeanalysis,
        rectificationmeasures:
            rectificationmeasures ?? this.rectificationmeasures,
        effectiveverification:
            effectiveverification ?? this.effectiveverification,
        status: status ?? this.status,
        handleuserId: handleuserId ?? this.handleuserId,
        handledatetime: handledatetime ?? this.handledatetime,
        createUid: createUid ?? this.createUid,
        createDate: createDate ?? this.createDate,
        writeUid: writeUid ?? this.writeUid,
        writeDate: writeDate ?? this.writeDate,
        lastSupOpTime: lastSupOpTime ?? this.lastSupOpTime,
        lastRefuseTime: lastRefuseTime ?? this.lastRefuseTime,
        comfirmTime: comfirmTime ?? this.comfirmTime);
  }

  @override
  String toString() {
    return '''PurchaseQualityProblem{
      id: $id,
      serialnumber: $serialnumber,
      documentno: $documentno,
      resaon: $resaon,
      spec: $spec,
      instockdate: $instockdate,
      instockqty: $instockqty,
      checkqty: $checkqty,
      unqualifiedqty: $unqualifiedqty,
      questiondescription: $questiondescription,
      treatmentmethod: $treatmentmethod,
      causeanalysis: $causeanalysis,
      rectificationmeasures: $rectificationmeasures,
      effectiveverification: $effectiveverification,
      status: $status,
      handleuserId: $handleuserId,
      handledatetime: $handledatetime,
      createUid: $createUid,
      createDate: $createDate,
      writeUid: $writeUid,
      writeDate: $writeDate,
      comfirmTime: $comfirmTime,
      lastSupOpTime: $lastSupOpTime,
      lastRefuseTime: $lastRefuseTime,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is PurchaseQualityProblem &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          serialnumber == other.serialnumber &&
          // productId == other.productId &&
          spec == other.spec &&
          resaon == other.resaon &&
          // supplierId == other.supplierId &&
          instockdate == other.instockdate &&
          instockqty == other.instockqty &&
          checkqty == other.checkqty &&
          unqualifiedqty == other.unqualifiedqty &&
          questiondescription == other.questiondescription &&
          treatmentmethod == other.treatmentmethod &&
          causeanalysis == other.causeanalysis &&
          rectificationmeasures == other.rectificationmeasures &&
          effectiveverification == other.effectiveverification &&
          status == other.status &&
          handleuserId == other.handleuserId &&
          handledatetime == other.handledatetime &&
          createUid == other.createUid &&
          createDate == other.createDate &&
          writeUid == other.writeUid &&
          comfirmTime == other.comfirmTime &&
          lastRefuseTime == other.lastRefuseTime &&
          lastSupOpTime == other.lastSupOpTime &&
          writeDate == other.writeDate);

  factory PurchaseQualityProblem.fromMap(Map<String, dynamic> map) {
    return new PurchaseQualityProblem(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      serialnumber: map['bh'] != false ? map['bh'].toString() as String? : "",
      documentno: map['documentno'],
      productName:
          map['clmc'] != false ? map['clmc'].toString() as String? : "",
      spec: map['spec'] != false ? map['spec'].toString() as String? : "",
      resaon: map['resaon'] != false ? map['resaon'].toString() as String? : "",
      supplierName:
          map['gysmc'] != false ? map['gysmc'].toString() as String? : "",
      instockdate: map['instockdate'] != false
          ? Utils.getDate(date: map['instockdate']).toString() as String?
          : "",
      instockqty:
          map['instockqty'] != false ? map['instockqty'].toString() : null,
      checkqty: map['checkqty'] != false ? num.parse(map['checkqty']) : 0,
      unqualifiedqty:
          map['unqualifiedqty'] != false ? num.parse(map['unqualifiedqty']) : 0,
      questiondescription:
          map['blqk'] != false ? map['blqk'].toString() as String? : "",
      treatmentmethod: map['treatmentmethod'] != false
          ? map['treatmentmethod'].toString() as String?
          : "",
      causeanalysis: map['causeanalysis'] != false
          ? map['causeanalysis'].toString() as String?
          : "",
      rectificationmeasures: map['rectificationmeasures'] != false
          ? map['rectificationmeasures'].toString() as String?
          : "",
      effectiveverification: map['effectiveverification'] != false
          ? map['effectiveverification'].toString() as String?
          : "",
      status: map['status'] != false ? map['status'].toString() as String? : "",
      handleuserId:
          map['handleuserId'] != false && map['handleuserId'][0] != false
              ? map['handleuserId'][0].toString() as String?
              : null,
      handleuserName:
          map['handleusername'] != false && map['handleusername'] != false
              ? map['handleusername'].toString() as String?
              : null,
      handledatetime: map['handledatetime'] != false
          ? map['handledatetime'].toString() as String?
          : null,
      createUid: map['create_uid'] != false
          ? map['create_uid'][0].toString() as String?
          : "",
      createName: map['create_uid'] != false
          ? map['create_uid'][1].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
      jianyanren: map['jianyanren'] != false
          ? map['jianyanren'].toString() as String?
          : "",
      jcrq: map['jcrq'] != false ? map['jcrq'].toString() as String? : "",
      cgb: map['cgb'] != false ? map['cgb'].toString() as String? : "",
      zlbpsyj:
          map['zlbpsyj'] != false ? map['zlbpsyj'].toString() as String? : "",
      isPush:
          map['is_push'] != false ? map['is_push'].toString() as String? : "",
      bhx: map['bhx'] != false ? map['bhx'].toString() as String? : "",
      comfirmTime: map['give_out_date'] is String ? map['give_out_date'] : '',
      lastSupOpTime:
          map['supplier_edit_date'] is String ? map['supplier_edit_date'] : '',
      lastRefuseTime:
          map['zlb_edit_date'] is String ? map['zlb_edit_date'] : '',
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'serialnumber': this.serialnumber,
      'productName': this.productName,
      'spec': this.spec,
      'resaon': this.resaon,
      'supplierName': this.supplierName,
      'jcrq': this.jcrq,
      'instockqty': this.instockqty,
      'checkqty': this.checkqty,
      'unqualifiedqty': this.unqualifiedqty,
      'questiondescription': this.questiondescription,
      'jianyanren': this.jianyanren,
      'zlbpsyj': this.zlbpsyj,
      'causeanalysis': this.causeanalysis,
      'rectificationmeasures': this.rectificationmeasures,
      'effectiveverification': this.effectiveverification,
      'status': this.status == '1' ? "已处理" : '提交',
      'handleuserName': this.handleuserName,
      'handledatetime': this.handledatetime,
      'createName': this.createName,
      'createDate': Utils.timeUTC(this.createDate),
      'cgb': this.cgb,
      'bhx': this.bhx,
      'give_out_date': this.comfirmTime,
      'supplier_edit_date': this.lastSupOpTime,
      'zlb_edit_date': this.lastRefuseTime,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.isPush != null && this.isPush != '')
        isPush == '1' ? ['is_push', '=', "1"] : ['is_push', '!=', "1"],
      if (this.serialnumber != null && this.serialnumber != '')
        ['serialnumber', '=', "${this.serialnumber}"],
      if (this.productName != null && this.productName != '')
        ['clmc', 'like', "%${this.productName}%"],
      if (this.supplierName != null && this.supplierName != '')
        ['gysmc', 'like', "%${this.supplierName}%"],
      if (this.status != null && this.status != '')
        ['status', '=', this.status!],
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + " 00:00:00", isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + " 23:59:59", isToBeijing: false)
        ],
    ];
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'serialnumber': this.serialnumber,
      'clmc': this.productName,
      'spec': this.spec,
      'resaon': this.resaon,
      'product_id': null,
      'supplier_id': null,
      'gysmc': this.supplierName,
      'instockqty': this.instockqty,
      'checkqty': this.checkqty,
      'unqualifiedqty': this.unqualifiedqty,
      'blqk': this.questiondescription,
      'treatmentmethod': this.treatmentmethod,
      'causeanalysis': this.causeanalysis,
      'rectificationmeasures': this.rectificationmeasures,
      'effectiveverification': this.effectiveverification,
      'status': this.status,
      'handleuserId': handleuserId != null && handleuserId != ''
          ? int.parse(handleuserId!)
          : null,
      'handledatetime': this.handledatetime,
      'create_uid': this.createUid,
      'create_date': this.createDate,
      'write_uid': this.writeUid,
      'write_date': this.writeDate,
      'jianyanren': jianyanren,
      'jcrq': jcrq,
      'cgb': cgb,
      'zlbpsyj': zlbpsyj,
      'is_push': isPush,
      'bhx': bhx,
      'handleusername': handleuserName,
      'give_out_date': comfirmTime
    } as Map<String, dynamic>;
  }

//</editor-fold>
}
